package com.kaiyidiannao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.OrderBean;
import com.kaiyidiannao.view.ScaleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mark on 2014/4/16.
 */
public class OrderSHopAdapter extends ImageLoaderBaseAdapter {

    private ImageLoader imageLoader;
    private LayoutInflater layoutInflater;
    private List<OrderBean> list = new ArrayList<OrderBean>();
    private Context context;

    public OrderSHopAdapter(Context context, List<OrderBean> list) {
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
        this.context = context;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        TextView shopName = null;
        TextView shopNum = null;
        ScaleImageView scaleImageView = null;

        OrderBean orderBean = list.get(position);
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.order_shop_item, null);
        }
        shopNum = (TextView)convertView.findViewById(R.id.shopNum);
        scaleImageView = (ScaleImageView) convertView.findViewById(R.id.order_shop_imageview);
        shopName = (TextView) convertView.findViewById(R.id.shopName);

        shopNum.setText(orderBean.getNumber()+"个");
        imageLoader.displayImage(orderBean.getThumb(),scaleImageView, options, null);
        shopName.setText(orderBean.getTitle());

        return convertView;
    }
}
